#
# Makefile
#

CROSS_COMPILR_DIR ?= /home/yd/owner/am335x/buildroot/output/host
CROSS_COMPILR ?= $(CROSS_COMPILR_DIR)/bin/arm-linux-
CC 	:= $(CROSS_COMPILR)gcc
CXX := $(CROSS_COMPILR)g++
LIB_DIR := -L$(CROSS_COMPILR_DIR)/lib -L$(CROSS_COMPILR_DIR)/lib64 
LVGL_DIR_NAME ?= lvgl
LVGL_DIR ?= ${shell pwd}
OBJ_DIR = ./obj
INSTALL_DIR=/nfs/root

CFLAGS = -Wall -Wshadow -Wundef -Wmaybe-uninitialized -I $(CROSS_COMPILR_DIR)/arm-buildroot-linux-gnueabihf/sysroot/usr
CFLAGS += -O0 -g0 -I$(LVGL_DIR)/
# CFLAGS ?= -O3 -g0 -I$(LVGL_DIR)/ -Wall -Wshadow -Wundef -Wmissing-prototypes -Wno-discarded-qualifiers -Wall -Wextra -Wno-unused-function -Wno-error=strict-prototypes -Wpointer-arith -fno-strict-aliasing -Wno-error=cpp -Wuninitialized -Wmaybe-uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default -Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic -Wno-sign-compare -Wno-error=missing-prototypes -Wdouble-promotion -Wclobbered -Wdeprecated -Wempty-body -Wtype-limits -Wshift-negative-value -Wstack-usage=2048 -Wno-unused-value -Wno-unused-parameter -Wno-missing-field-initializers -Wuninitialized -Wmaybe-uninitialized -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wpointer-arith -Wno-cast-qual -Wmissing-prototypes -Wunreachable-code -Wno-switch-default -Wreturn-type -Wmultichar -Wno-discarded-qualifiers -Wformat-security -Wno-ignored-qualifiers -Wno-sign-compare
LDFLAGS ?= -lm -lts -linput $(LIB_DIR)
BIN = demo


#Collect the files to compile
MAINSRC = ./main.c

include $(LVGL_DIR)/lvgl/lvgl.mk
include $(LVGL_DIR)/lv_drivers/lv_drivers.mk
include $(LVGL_DIR)/lv_demos/lv_demo.mk

OBJEXT ?= .o

AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))

MAINOBJ = $(MAINSRC:.c=$(OBJEXT))

SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
OBJS = $(AOBJS) $(COBJS)

## MAINOBJ -> OBJFILES

all: default

%.o: %.c
	@$(CC)  $(CFLAGS) -c $< -o $@
	@echo "CC $<"
    
default: $(AOBJS) $(COBJS) $(MAINOBJ)
	@$(CC) -o $(BIN) $(MAINOBJ) $(AOBJS) $(COBJS) $(LDFLAGS)
	@mkdir -p $(OBJ_DIR)
	@cp demo $(OBJ_DIR)
	@sudo cp demo $(INSTALL_DIR)
	@rm -f $(BIN) $(AOBJS) $(COBJS) $(MAINOBJ)

clean: 
	rm -f $(BIN) $(AOBJS) $(COBJS) $(MAINOBJ)

